<!-- 续费审核 -->
<template>
  <div class="page-container">
    续费
    <div class="table-page-search">
      <a-form>
        <a-form-item label="负责人姓名">
          <a-input v-model="queryParam.leadingName" placeholder="请输入负责人姓名" allowClear />
        </a-form-item>
        <a-form-item label="审核状态">
          <a-select v-model="queryParam.auditStatus" placeholder="请选择" allowClear>
            <a-select-option
              v-for="dict in Dict.getLocal('reviewStatusDict')"
              :key="dict.dictValue"
              :value="dict.dictValue"
            >
              {{ dict.dictLabel }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <span class="search-submitButtons">
          <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
          <a-button @click="handleReset">重置</a-button>
        </span>
      </a-form>
    </div>
    <s-table
      ref="table"
      size="default"
      rowKey="id, enabled, title"
      :columns="newColumns"
      :data="loadData"
      :rowSelection="null"
    >
      <!-- 序号 -->
      <span slot="serial" slot-scope="text, record, index">
        {{ (pagination.current - 1) * pagination.pageSize + parseInt(index) + 1 }}
      </span>
      <!-- 用户类型 -->
      <span slot="applyType" slot-scope="text, record, index">
        <DictTag :options="Dict.getLocal('applyTypeDict')" :value="record.applyType" isText showBorder />
      </span>
      <!-- 审核状态 -->
      <span slot="auditStatus" slot-scope="text">
        <DictTag :options="Dict.getLocal('reviewStatusDict')" :value="text" />
      </span>
      <!-- 缴费情况 -->
      <span slot="paymentStatus" slot-scope="text">
        <DictTag :options="Dict.getLocal('paymentStatusDict')" :value="text" />
      </span>

      <!-- 缴费方式 -->
      <span slot="payMode" slot-scope="text">
        {{ text | getPayModeText }}
      </span>

      <!-- 操作 -->
      <div slot="actionFilterIcon" class="disFlxAC min-width-12">
        <CustomTable :name="$route.name + '_' + 'Renew'" :columns="columns" :newColumns="newColumns" />
      </div>
      <template slot="actionFilter">
        <div></div>
      </template>
      <span slot="action" slot-scope="text, record">
        <ButtonGroup :max-length="2" :key="`${record.auditStatus}`">
          <a-button
            v-for="item in _btnList(record)"
            :key="item.text"
            type="primary"
            ghost
            size="small"
            class="width-8"
            @click="item.fn"
          >
            {{ item.text }}
          </a-button>
        </ButtonGroup>
      </span>
    </s-table>

    <PayApproval ref="payApproval" @success="handleReload" />
  </div>
</template>

<script>
import { STable } from '@/components'
import { customFormStage, RenewOfflineMemberOrderList } from '@/api/member/member'
import { payModeDict } from '@/api/order/order'
import CustomTable from '@/components/Cuscolumn'
import PayApproval from './payApproval.vue'
import { checkPermission } from '@/utils/authority'
import DictTag from '@/components/DictTag'
import ButtonGroup from '@/components/Table/buttonGroup'

export default {
  components: {
    STable,
    CustomTable,
    PayApproval,
    DictTag,
    ButtonGroup
  },
  data() {
    return {
      pagination: {
        current: 1,
        pageSize: 10
      },
      queryParam: {
        leadingName: undefined,
        auditStatus: undefined
      },
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' },
          width: '80px'
        },
        {
          title: '用户类型',
          dataIndex: 'applyType',
          ellipsis: true,
          scopedSlots: { customRender: 'applyType' },
          width: '100px'
        },
        {
          title: '会员名称',
          dataIndex: 'memberName',
          ellipsis: true,
          width: '180px'
        },
        {
          title: '当前职务',
          dataIndex: 'nowLevelName',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '申请职务',
          dataIndex: 'levelName',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '负责人姓名',
          dataIndex: 'leadingName',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '负责人手机',
          dataIndex: 'leadingPhone',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '会费标准',
          dataIndex: 'money',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '实缴金额',
          dataIndex: 'payMoney',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '缴费方式',
          dataIndex: 'payMode',
          ellipsis: true,
          width: '150px',
          scopedSlots: { customRender: 'payMode' }
        },
        {
          title: '审核状态',
          dataIndex: 'auditStatus',
          ellipsis: true,
          scopedSlots: { customRender: 'auditStatus' },
          width: '150px'
        },
        {
          title: '审核时间',
          dataIndex: 'auditTime',
          ellipsis: true,
          width: '180px'
        },
        {
          title: '操作',
          width: '185px',
          dataIndex: 'action',
          fixed: 'right',
          scopedSlots: {
            customRender: 'action',
            filterDropdown: 'actionFilter',
            filterIcon: 'actionFilterIcon'
          }
        }
      ],
      pageNum: 1,
      // 加载数据方法 必须为 Promise 对象
      loadData: async parameter => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize
        }
        this.listLoading = true
        return RenewOfflineMemberOrderList(Object.assign(params, this.queryParam))
          .then(res => {
            this.listLoading = false
            if (res.code === 0) {
              this.pagination.current = parameter.pageNum
              this.pagination.pageSize = parameter.pageSize
              return res
            } else {
              this.$message.error(res.msg)
            }
          })
          .catch(err => {
            this.listLoading = false
            this.$message.error(err.msg)
          })
      },
      stageList: []
    }
  },
  filters: {
    getPayModeText(text) {
      return payModeDict.find(v => v.value === text).label
    }
  },
  computed: {
    newColumns() {
      const currentColumns = this.$store.state.user.customTable
      if (currentColumns && currentColumns[this.$route.name + '_' + 'Renew']) {
        return this.$options
          .data()
          .columns.filter(v => {
            const _items = currentColumns[this.$route.name + '_' + 'Renew'].find(
              item => item === v.title || item.title === v.title
            )
            if (_items) return Object.assign(v, _items)
          })
          .sort((a, b) => {
            return a.tableSort - b.tableSort
          })
      } else {
        return this.columns
      }
    }
  },
  created() {},
  methods: {
    handleReload() {
      this.$refs.table.refresh()
    },
    //入会审核操作
    handleApproval(row, action) {
      this.$refs.payApproval.show({
        id: row.id,
        memberId: row.memberId,
        action
      })
    },
    async getCustomFormStage(id) {
      let res = await customFormStage(id)
      this.stageList = res.data || []
    },
    handleReset() {
      Object.keys(this.queryParam).forEach(k => {
        this.queryParam[k] = undefined
      })
      this.$refs.table.refresh(true)
    },
    _btnList(record) {
      let oldList = [
        {
          show: checkPermission('member:approval:renewDetail'),
          text: '详情',
          fn: () => this.handleApproval(record, 'detail')
        },
        {
          show: record.auditStatus === 0 && checkPermission('member:approval:renew:proofApproval'),
          text: '凭证审核',
          fn: () => this.handleApproval(record, 'approval')
        }
      ]
      return oldList.filter(v => v.show)
    }
  }
}
</script>
<style scoped lang="less"></style>
